﻿using System;
using System.Collections.Generic;
using System.Xml;

namespace myWindowsMediaPlayer
{
    public class AudioPlaylist : IPlaylist
    {
        public AudioPlaylist(List<string> list)
        {
            foreach (string str in list)
            {
                PlaylistItem PlI = new PlaylistItem(str);
                _playlist.Add(PlI);
            }
        }

        public override void Serialize(string playlistName)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.IndentChars = ("    ");
            String fileName = playlistName + ".xml";
            Console.WriteLine(fileName);

            using (XmlWriter writer = XmlWriter.Create(fileName, settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("AudioPlaylist");
                foreach (PlaylistItem plI in _playlist)
                {
                    writer.WriteStartElement("Track");
                    writer.WriteElementString("title", plI._title);
                    writer.WriteElementString("artist", plI._artist);
                    writer.WriteElementString("album", plI._album);
                    writer.WriteElementString("trackNum", plI._trackNum);
                    writer.WriteElementString("year", plI._year);
                    writer.WriteElementString("comment", plI._comment);
                    writer.WriteElementString("genre", plI._genre);
                    writer.WriteElementString("length", plI._length);
                    writer.WriteElementString("path", plI._path);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
                writer.Flush();
                writer.Close();
            }
        }
    }
}
